# 导入selenium

from selenium import webdriver
from selenium.webdriver.common.by import By

DRIVER_PATH = './chromedriver.exe'
BROWSER = webdriver.Chrome(DRIVER_PATH)
TARGET_URL = 'https://www.baidu.com/'
BROWSER.get(TARGET_URL)

content = BROWSER.page_source
# print(content)

# 元素定位
# <selenium.webdriver.remote.webelement.WebElement
# (session="04d5c2fd89aa5fdf0c7bb0b44fada288", element="ee1a6a84-976e-4f44-b1b5-927406fe4211")>
button = BROWSER.find_element_by_id('su')
print(button)

# name属性=wd的元素
# <selenium.webdriver.remote.webelement.WebElement
# (session="329cc7cb1c1a06c28e557d3ab7d6c46d", element="5b2973a0-4fce-47e5-a47c-6191ba76a1b9")>
wdInput = BROWSER.find_element_by_name('wd')
print(wdInput)

# 返回第一个元素
# BROWSER.find_element_by_xpath()
suInput = BROWSER.find_element_by_xpath('//input[@id="su"]')
print(suInput)

# 返回元素集合
# BROWSER.find_elements_by_xpath()
suInput = BROWSER.find_elements_by_xpath('//input[@id="su"]')
print(suInput)

# 按标签名
# p = BROWSER.find_elements_by_tag_name('p')
# print(p)

# 按CSS选择器
# p = BROWSER.find_element_by_css_selector('p')
# print(p)


